<%@ page language="java"  pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>后台菜单</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<LINK href="<%=basePath%>resource/css/admin.css" type="text/css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>scripts/extjs/resources/css/ext-all.css" />   
	<script type="text/javascript" src="<%=basePath%>scripts/extjs/adapter/ext/ext-base.js"></script> 
	<script type="text/javascript" src="<%=basePath%>scripts/extjs/ext-all.js"></script> 
	<script type="text/javascript" src="<%=basePath%>scripts/jquery-1.4.2.js"></script>
    <script type="text/javascript">
         var basePath="<%=basePath%>";
         var levelid="${adminUser.id}";
         var  levelbase=basePath+'adminloign/getLevle.shtml';
    
              
       Ext.onReady(function(){    
     
    var Tree = Ext.tree;   
    var tree = new Tree.TreePanel({    
        el:Ext.getBody(),    
        autoScroll:true,
        draggable:false,    
        animate:true,    
        enableDD:true,    
        containerScroll: true,    
       loader: new Tree.TreeLoader({    
            dataUrl:basePath+'tree/getTree.shtml?id=0'   
        }) 
   
    });    
    var root = new Tree.AsyncTreeNode({    
        text: '后台管理',    
        draggable:false,    
        id:'0'
    }); 

      tree.setRootNode(root);  
      
      tree.on('click', function (node, e) {
            e.stopEvent();
            if (node.isLeaf()) {
              
               self.parent.frames["main"].location.href=node.attributes.href;
            } else {
                node.toggle();
            }
        });
      
        
      tree.on('beforeload',function(node){ 
         var  a=basePath+'tree/getTree.shtml?id='+node.id; 
         tree.loader.dataUrl=a
         
     }); 
      $.ajax({
                    url: levelbase,
                    cache: false,
                    data: "id="+levelid,
                    success: function(msg){
                         
                        var obj=eval('('+msg+')');
                        var result=obj[0]["message"];
                 
                      if(result=="0"){
                       //定义鼠标右键上下文菜单
                            tree.on('contextmenu',function(node,e){
             if(node.id==0){
              var rightClick = new Ext.menu.Menu({ 
                id :'rightClickCont', 
        items : [{ 
          id:'delete', 
          text : '删除' ,
          handler:function (){
                var id=node.id ; 
                top.frames[2].location=basePath+"back/jsp/deletemenu.jsp?id="+id;
               
       } 
          }, { 
           id:'add', 
           text : '增加',
            handler:function (){
                var id=node.id ; 
           top.frames[2].location=basePath+"back/jsp/addMenu.jsp?id="+id;
       } 
          }] 
         }); 
         }else{
                var rightClick = new Ext.menu.Menu({ 
       id :'rightClickCont', 
      items : [{ 
        id:'edit', 
        text : '编辑', 
       handler:function (){
          var id=node.id 
          top.frames[2].location=basePath+"tree/queryMenu.shtml?id="+id;
       } 
       }, { 
          id:'delete', 
          text : '删除',
           handler:function (){
                var id=node.id ; 
                top.frames[2].location=basePath+"back/jsp/deletemenu.jsp?id="+id;
               
       }  
          }, { 
           id:'add', 
           text : '增加',
            handler:function (){
            var id=node.id ; 
            top.frames[2].location=basePath+"back/jsp/addMenu.jsp?id="+id;
       } 
          }] 
         }); 
         }
      e.preventDefault(); 
      rightClick.showAt(e.getXY());
       }
     
     );
                         
                  }
               
                      
                 }
                });
    
   
     tree.render();    
     root.expand();  
    }); 
    
    </script> 
  </head>
  
  <body>
    
  </body>
</html>
